package com.pactera.controller.common.web;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;

import com.alibaba.fastjson.JSONObject;
import com.pactera.common.constants.Constants;
import com.pactera.common.file.FileUtils;
import com.pactera.common.utils.MediaTypes;

import springfox.documentation.annotations.ApiIgnore;

@ApiIgnore
@Controller
@RequestMapping(value = "/upload")
public class UploadController {
	
    /**
     * 方法描述：上传文件
     * @param file
     * @param component
     * @param request
     * @param response
     * @throws Exception void
     */
   @RequestMapping(value = "/file", method = RequestMethod.POST)
   public void uploadrequestfile(@RequestParam MultipartFile file,HttpServletRequest request, HttpServletResponse response) throws Exception {
	   response.setContentType(MediaTypes.TEXT_HTML_UTF_8);
	   
	   Map<String, Object> resultData = FileUtils.uploadFile(request, file,Constants.UPLOAD_ROOT);
	   String jsonStr = JSONObject.toJSONString(resultData);
	   response.getWriter().print(jsonStr);
   }
}
